package tags;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

public class ColorTag extends TagSupport
{
	private static final long serialVersionUID = 6829172953325165304L;
	private PageContext pageContext = null;
	private Tag parent = null;	
	private int num;
	
	public void setNum(int n)
	{
		num = n;
	}

	@Override
	public int doEndTag() throws JspException
	{
		System.out.println("doEndTag()");
		return EVAL_PAGE;
	}
	
	@Override
	public int doStartTag() throws JspException
	{
		System.out.println("ColorTag.doStartTag()");
		
		Double c = new Double(num / 2.0);
		String test = c.toString();
		System.out.println("test = " + test);
		test = test.replaceAll( "(.*)\\.", "" );
		System.out.println("test = " + test);
		if(test.equals( "5" ))
		{
			pageContext.setAttribute( "class", "row2" );
			return EVAL_BODY_INCLUDE;
		}
		else
		{
			pageContext.setAttribute( "class", "row1" );
			return EVAL_BODY_INCLUDE;
		}
	}
	
	@Override
	public Tag getParent()
	{
		return parent;
	}
	
	@Override
	public void release()
	{
		// TODO Auto-generated method stub
		
	}
	
	@Override
	public void setPageContext( PageContext pc )
	{
		pageContext = pc;
	}
	
	@Override
	public void setParent( Tag t )
	{
		parent = t;
	}
}